global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    monitor: 'codelab-monitor'

rule_files:
- "rules/*.yml"

alerting:
  alertmanagers:
  - static_configs:
    - targets:
      - {{hostvars[inventory_hostname]['ansible_default_ipv4']['address']}}:9093

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']
  
  - job_name: 'node-exporter'
    static_configs:
      - targets:
      {% for host in groups['required_exporters'] %}
        - {{ hostvars[host]['intranet_ip'] }}:9100
      {% endfor %}

  - job_name: 'docker_daemon'
    static_configs:
      - targets:
      {% for host in groups['required_exporters'] %}
        - {{ hostvars[host]['intranet_ip'] }}:9323
      {% endfor %}

  - job_name: 'docker_exporter'
    static_configs:
      - targets:
      {% for host in groups['required_exporters'] %}
        - {{ hostvars[host]['intranet_ip'] }}:9417
      {% endfor %}

  - job_name: 'nacos_metrics'
    metrics_path: '/nacos/actuator/prometheus'
    static_configs:
      - targets:
      {% for host in groups['nacos_clusters'] %}
        - {{ hostvars[host]['intranet_ip'] }}:{{ hostvars[host]['port'] | default('8848') }}
      {% endfor %}

  - job_name: 'pgsql_metrics'
    static_configs:
      - targets:
      {% for host in groups['middleware_exporters'] %}
        - {{ hostvars[host]['intranet_ip'] }}:9187
      {% endfor %}

  - job_name: 'redis_exporter'
    static_configs:
      - targets:
      {% for host in groups['middleware_exporters'] %}
        - {{ hostvars[host]['intranet_ip'] }}:9121
      {% endfor %}

  - job_name: 'rocketmq_exporter'
    static_configs:
      - targets:
      {% for host in groups['middleware_exporters'] %}
        - {{ hostvars[host]['intranet_ip'] }}:5557
      {% endfor %}

  - job_name: 'jmx_exporter'
    file_sd_configs:
      - files: [ 'sd-files/jmx-*.yml' ]

  - job_name: 'nginx_exporter'
    file_sd_configs:
      - files: [ 'sd-files/nginx-*.yml' ]